﻿using ConfExpert.Forms.Base;
using ConfExpert.Utility;
using DevExpress.XtraEditors;
using DevTeam;
using System;

namespace ConfExpert.Forms.Siparisler
{
    public partial class YuklemeFormlari2 : XForm
    {
        public YuklemeFormlari2()
        {
            InitializeComponent();
        }

        private void YuklemeFormlari2_Load(object sender, EventArgs e)
        {
            gridView1.Init("GetYuklemeFormlari");
            gridView1.AddDetailGrid(gridView2, "YuklemePartisiId");

            gridView1.FormatAsNumber(0, "Toplam");
            gridView2.FormatAsNumber(0, "Toplam");
            gridView1.AddSummary("Toplam");
            gridView2.AddSummary("Toplam");

            GridManager gm = GridManager.GetManager(gridView1);
            gm.GridMenu.AddMenu("Packing List", PL);
            gm.GridMenu.AddMenu("Yükleme Formu", YuklemeFormuGoster);
            gm.GridMenu.AddMenu("İşlendi olarak işaretle", Done, true);

            splitContainerControl1.AutoSize();
            gridView1.MakeRowSelectable();
            gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            gridView1.MakeColumnVisible("InsertedOn");

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }

        void Done(object sender, EventArgs e)
        {
            ShowErrorMessage("Yakında!");
        }

        void YuklemeFormuGoster(object sender, EventArgs e)
        {
            int YuklemePartisiId = gridView1.GetFocusedDataRow()["YuklemePartisiId"].ToInt();
            if (YuklemePartisiId > 0)
            {
                using (YuklemeFormu2 f = new YuklemeFormu2(YuklemePartisiId))
                    f.ShowDialog();
            }
        }


        void PL(object sender, EventArgs e)
        {
            int YuklemePartisiId = gridView1.GetFocusedDataRow()["YuklemePartisiId"].ToInt();
            if (YuklemePartisiId > 0)
                AppSession.MainForm.ShowMdiChildForm(typeof(PackingList), YuklemePartisiId);
            /*
                using (PackingList pl = new PackingList(YuklemePartisiId))
                    pl.ShowDialog();
             */
            else
                XtraMessageBox.Show("Yükleme Partisi oluşturulmuş satırların çeki listesi alınabilir.");
        }
    }
}
